<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>CIS-MSP</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/admin.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/huazhi/images/favicon.ico"/>
</head>
<style>
    html,
    body,
    #container {
        width: 100%;
        height: 100%;
        color: #666
    }

    .divhtml {
        line-height: 20px;
        padding: 9px 0px;
        text-align: left;
        position: relative;
        display: block;
        float: left;
        font-weight: 400;
    }

    label, .btn {
        font-size: 14px;
        margin-left: 16px;
    }

    label {
        margin-bottom: 0px;
    }

    .layui-form-label {
        width: 120px;
    }

    .amap-logo, .amap-copyright {
        display: none !important;
    }

    .change_camera_direction {
        text-align: center;
        position: absolute;
        top: 8%;
        width: 200px;
        height: 200px;
    }

    .change_camera_direction .camera_title {
        color: white;
        font-size: 15px;
        margin: 5% auto;
    }

    .direction_content {
        width: 100%;
        height: 70%;
        position: relative;
    }

    .direction_div {
        position: relative;
        width: 30px;
        height: 30px;
    }

    .direction_div img {
        width: 100%;
        height: 100%;
    }

    /*left*/
    .left_direction {
        top: 5%;
        left: 20%;
    }

    /*bottom*/
    .bottom_direction {
        top: 5%;
        left: 40%;
    }

    /*right*/
    .right_direction {
        top: -39%;
        left: 61%;
    }

    /*top*/
    .top_direction {
        top: 2%;
        left: 40%;
    }

</style>
<body>
<div class="layui-fluid">
    <input type="hidden" id="videoTid" value="">
    <input type="hidden" id="videoUrl" value="">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this ">水泵当前状态</li>
                    <li>视频监控</li>
                    <li>设备参数</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form" lay-filter="component-form-element" id="formAttribute1"
                              action="">
                            <div class="layui-tab layui-tab-card">
                                <div class="layui-tab-content">
                                    <div class="layui-tab-item layui-show">
                                        <div class="layui-card-body layui-row layui-col-space10">
                                            <div class="layui-col-md12">
                                                <div class="layui-col-md12"
                                                     style="padding: 0px;border: 1px solid #f2f2f2;padding: 10px;">
                                                    <div class="layui-col-md12">
                                                        <div class="layui-form-item" style="margin-bottom: 0px;">
                                                            <div class="layui-inline">
                                                                <label class="layui-form-label" style="padding: 9px 1px;"> 产水泵状态：</label>
                                                                <div class="layui-input-inline divhtml" style="width: 30px;">
                                                                    <img src="<%=request.getContextPath()%>/images/222.png">
                                                                </div>
                                                            </div>
                                                            <div class="layui-inline">
                                                                <label class="layui-form-label" style="padding: 9px 1px;">鼓风机状态：</label>
                                                                <div class="layui-input-inline divhtml" style="width: 30px;">
                                                                    <img src="<%=request.getContextPath()%>/images/122.png">
                                                                </div>
                                                            </div>
                                                            <div class="layui-inline">
                                                                <label class="layui-form-label" style="padding: 9px 1px;">回流状态：</label>
                                                                <div class="layui-input-inline divhtml" style="width: 30px;">
                                                                    <img src="<%=request.getContextPath()%>/images/122.png">
                                                                </div>
                                                            </div>
                                                            <div class="layui-inline">
                                                                <label class="layui-form-label" style="padding: 9px 1px;">反洗泵状态：</label>
                                                                <div class="layui-input-inline divhtml" style="width: 30px;">
                                                                    <img src="<%=request.getContextPath()%>/images/222.png">
                                                                </div>
                                                            </div>
                                                            <div class="layui-inline">
                                                                <label class="layui-form-label" style="padding: 9px 1px;">搅拌机状态：</label>
                                                                <div class="layui-input-inline divhtml" style="width: 30px;">
                                                                    <img src="<%=request.getContextPath()%>/images/122.png">
                                                                </div>
                                                            </div>
                                                            <div class="layui-inline">
                                                                <label class="layui-form-label" style="padding: 9px 1px;">进水泵状态：</label>
                                                                <div class="layui-input-inline divhtml" style="width: 30px;">
                                                                    <img src="<%=request.getContextPath()%>/images/122.png">
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <img src="<%=request.getContextPath()%>/huazhi/images/sw21.gif"
                                                         style="width:100%;height: auto">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-col-xs12" style="color:#104E8B;">
                            <div class="layuiadmin-card-text" style="color:#104E8B;" style="float: left">
                                <video
                                        id="myPlayer"
                                        autoplay
                                        src=""
                                        controls
                                        width="1000"
                                        height="500"
                                        playsInline
                                        webkit-playsinline
                                >
                                </video>

                            </div>
                        </div>
                        <div class="change_camera_direction" style="float: right">
                            <div class="camera_title" style="color: #000">摄像头方向控制</div>
                            <div class="direction_content">
                                <div class="direction_div top_direction">
                                    <button onclick="control(0)" type="button"
                                            class="layui-btn layui-btn-normal layui-btn-sm">↑
                                    </button>
                                </div>
                                <div class="direction_div left_direction">
                                    <button onclick="control(2)" type="button"
                                            class="layui-btn layui-btn-normal layui-btn-sm">←
                                    </button>
                                </div>
                                <div class="direction_div bottom_direction">
                                    <button onclick="control(1)" type="button"
                                            class="layui-btn layui-btn-normal layui-btn-sm">↓
                                    </button>
                                </div>
                                <div class="direction_div right_direction">
                                    <button onclick="control(3)" type="button"
                                            class="layui-btn layui-btn-normal layui-btn-sm">→
                                    </button>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item layui-layout-admin">
                            <div class="layui-input-block">
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-col-md6">
                            <div class="layui-col-md12 layui-col-space10"
                                 style="margin-top:5px;">
                                <div class="layui-col-md8" id="doman1"
                                     style="padding-bottom:0px;">


                                    <div class="layui-form-item"
                                         style="margin-bottom: 0px;">
                                        <div class="layui-col-lg10">
                                            <label class="layui-form-label"
                                                   style="padding-right: 0px;">设备名称：</label>
                                            <div class="layui-input-block" style="margin-left:80px;">
                                                <div class="divhtml">
                                                    YZLWSZHL-00001 | 中海龙测试设备
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item"
                                         style="margin-bottom: 0px;">
                                        <div class="layui-col-lg10">
                                            <label class="layui-form-label"
                                                   style="padding-right: 0px;">产水泵启动时间：</label>
                                            <div class="layui-input-block" style="margin-left:80px;">
                                                <div class="divhtml">8.00
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item"
                                         style="margin-bottom: 0px;">

                                        <div class="layui-col-lg12">
                                            <label class="layui-form-label" style="padding-right: 0px;">反洗泵启动时间：</label>
                                            <div class="layui-input-block" style="margin-left:80px;">
                                                <div class="divhtml">
                                                    3.00
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item"
                                         style="margin-bottom: 0px;">

                                        <div class="layui-col-lg112">
                                            <label class="layui-form-label"
                                                   style="padding-right: 0px;">
                                                鼓风机启动时间：</label>
                                            <div class="layui-input-block"
                                                 style="margin-left:80px;">

                                                <div class="divhtml">
                                                    180.00
                                                </div>


                                            </div>

                                        </div>

                                    </div>

                                    <div class="layui-form-item"
                                         style="margin-bottom: 0px;">

                                        <div class="layui-col-lg12">
                                            <label
                                                    class="layui-form-label"
                                                    style="padding-right: 0px;">
                                                搅拌机启动时间：</label>

                                            <div class="layui-input-block"
                                                 style="margin-left:80px;">
                                                <div class="divhtml">
                                                    20.00
                                                </div>

                                            </div>

                                        </div>
                                        <div class="layui-form-item"
                                             style="margin-bottom: 0px;">

                                            <div class="layui-col-lg12">
                                                <label
                                                        class="layui-form-label"
                                                        style="padding-right: 0px;">
                                                    回流泵启动时间：</label>
                                                <div class="layui-input-block"
                                                     style="margin-left:80px;">
                                                    <div class="divhtml">
                                                        5.00
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-col-md4" id="doman2"
                                     style="padding-bottom:0px;">
                                    <div class="layui-form-item"
                                         style="margin-bottom: 0px;">
                                        <div class="layui-col-lg10">
                                            <label class="layui-form-label" style="padding-right: 0px;">设备吨位：</label>
                                            <div class="layui-input-block" style="margin-left:80px;">
                                                <div class="divhtml">10吨</div>
                                            </div>

                                        </div>

                                    </div>

                                    <div class="layui-form-item"
                                         style="margin-bottom: 0px;">

                                        <div class="layui-col-lg12">
                                            <label
                                                    class="layui-form-label"
                                                    style="padding-right: 0px;">
                                                产水泵停止时间：</label>
                                            <div class="layui-input-block"
                                                 style="margin-left:80px;">

                                                <div class="divhtml">
                                                    2.00
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item"
                                         style="margin-bottom: 0px;">
                                        <div class="layui-col-lg12">
                                            <label
                                                    class="layui-form-label"
                                                    style="padding-right: 0px;">
                                                反洗泵停止时间：</label>

                                            <div class="layui-input-block"
                                                 style="margin-left:80px;">

                                                <div class="divhtml">
                                                    60.00
                                                </div>

                                            </div>

                                        </div>

                                    </div>

                                    <div class="layui-form-item"
                                         style="margin-bottom: 0px;">

                                        <div class="layui-col-lg12">
                                            <label
                                                    class="layui-form-label"
                                                    style="padding-right: 0px;">
                                                鼓风机停止时间：</label>

                                            <div class="layui-input-block"
                                                 style="margin-left:80px;">
                                                <div class="divhtml">
                                                    60.00
                                                </div>

                                            </div>

                                        </div>

                                    </div>

                                    <div class="layui-form-item"
                                         style="margin-bottom: 0px;">

                                        <div class="layui-col-lg12">
                                            <label class="layui-form-label" style="padding-right: 0px;">搅拌机停止时间：</label>

                                            <div class="layui-input-block" style="margin-left:80px;">
                                                <div class="divhtml">5.00</div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item"
                                         style="margin-bottom: 0px;">
                                        <div class="layui-col-lg12">
                                            <label
                                                    class="layui-form-label"
                                                    style="padding-right: 0px;">
                                                回流泵停止时间：</label>

                                            <div class="layui-input-block"
                                                 style="margin-left:80px;">
                                                <div class="divhtml">
                                                    60.00
                                                </div>

                                            </div>

                                        </div>

                                    </div>

                                </div>

                            </div>
                        </div>
                        <div class="layui-form-item layui-layout-admin">
                            <div class="layui-input-block">
                                <%--                                <div class="layui-footer" style="left: 0;padding: 0px;">--%>
                                <%--                                    <button class="layui-btn" lay-submit lay-filter="*" >立即提交</button>--%>
                                <%--                                </div>--%>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/js/ezuikit.js"></script>
<script>
    var curWwwPath = window.document.location.href;
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    var localhostPaht = curWwwPath.substring(0, pos);
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    var serial = ''
    var Token = 'at.djmrc1l76kk8q9r26nvai1w77yc8z99w-1e6jr6wq87-1tbux0a-rqqqnkwgz';

    function child(videotid, videoUrl) {
        layui.use(['table', 'form', 'layer'/*, 'alert'*/], function () {
            var $ = layui.$
                , table = layui.table
                , form = layui.form
                , layer = layui.layer;


            var data = {
                deviceSerial: 'E42012633',
                channelNo: '1'
            }

            data.deviceSerial = videotid
            serial = videotid
            getToken();
            //eg:videoUrl:ezopen://open.ys7.com/086f83b73aa74dc39a053aadb50b58fb.live
            $('#myPlayer').attr("src", videoUrl);
            var player = new EZUIKit.EZUIPlayer('myPlayer');
        });
    }

    var control = function (direction) {
        var data = {}
        data.accessToken = Token;
        data.direction = direction;//控制方式
        data.speed = '1';//转动速度
        data.deviceSerial = serial
        data.channelNo = 1
        layui.use(['jquery', 'layer'], function () {
            var $ = layui.$
                , layer = layui.layer;
            $.post('https://open.ys7.com/api/lapp/device/ptz/start', data, function (res) {

                if (res.code == 200) {
                    layer.msg("摄像头移动中，请稍后", {time: 9000});
                    sleep(50);
                    stop();
                } else if (res.code == 10002) {
                    getToken();
                } else {

                }
            }, 'json');
            return false;
        });
    }


    var getToken = function () {
        var data1 = {appKey: 'f9cdc3af74d148d18e12b42bb4298b8b', appSecret: 'a16cae3a4495c0b291951dc6efd742fb'};
        layui.use(['jquery', 'layer'], function () {
            var $ = layui.$
                , layer = layui.layer;
            $.post(' https://open.ys7.com/api/lapp/token/get', data1, function (res) {
                if (res.code == 200) {
                    Token = res.data.accessToken;
                } else {
                    layer.msg(res.msg, {time: 2000});
                }
            }, 'json');
            return false;
        });

    }

    //停止转动
    var stop = function () {
        var data = {}
        data.accessToken = Token;


        data.deviceSerial = serial
        data.channelNo = 1
        layui.use(['jquery', 'layer'], function () {
            var $ = layui.$
                , layer = layui.layer;
            $.post('https://open.ys7.com/api/lapp/device/ptz/stop', data, function (res) {
                if (res.code == 200) {

                } else {
                    layer.msg(res.msg, {time: 2000});
                }
            }, 'json');
            return false;
        });
    }

    function sleep(n) {
        var start = new Date().getTime();
        //  console.log('休眠前：' + start);
        while (true) {
            if (new Date().getTime() - start > n) {
                break;
            }
        }
        // console.log('休眠后：' + new Date().getTime());
    }


</script>
</body>
</html>
